<?php
$zTemplate->set_file ( 'main', '../templates/showpics.html' );

$db = phpclone($dbObj);

$sql = "SELECT * FROM `org_details` WHERE `temp_userid` = '".$id."'";
$tRecordSet = $db -> getOneQuery($sql);

if($tRecordSet)
{
	$busIdentId = $tRecordSet['usr_id'];
	$businessName = getUsrNickName($busIdentId);
	/*
 	* DEAL WITH THE PICTURE FIELD
 	*/
	$sql = "SELECT * FROM `cs_photo_magt` WHERE `usr_id` = '".$busIdentId."'";
	$rs = $db -> executeQuery($sql);
	if ($rs)
	{
		$zTemplate->set_block ( 'main', 'optMenu', 'Msglist' );
		foreach ($rs as $val)
		{
			$zTemplate -> set_var(array('picPath'=>$recourcePath.$busIdentId.'/'.$val['source_img'],'picDesc'=>$val['pic_desp'],'picPath_s'=>$thumbnailPath.$busIdentId.'/'.$val['thumb_img']));
			$zTemplate->parse ( 'Msglist', 'optMenu', true );
		}
	}
	$zTemplate->set_var(array("NickName"=>$businessName,"BusAddress" =>$tRecordSet['curr_addr'],"BusTel"=>$tRecordSet['usr_phone']));
	$zTemplate->set_var(array("BusMail"=>$tRecordSet['usr_mails'],"BusWeb" =>$tRecordSet['website'],"BusFax"=>$tRecordSet['fax']));
}

/*
 * Relevant Merchants
 * Rules:
 * 	> firstly reommand the ones with the same city and same type
 * 	 > secondly choose the ones with only the same type
 */
$zTemplate->set_block ( 'main', 'optContent', 'ContentList' );

$sql = "SELECT * FROM `org_details` WHERE `city_id` = '".$tRecordSet['city_id']."' AND `sort_id` = '".$tRecordSet['sort_id']."' ORDER BY `hits` DESC LIMIT 0,5";
$rs = $db -> executeQuery($sql);
if($rs)
{
	foreach ($rs as $val)
	{
		if($val['temp_userid'] == $id) continue;
		$zTemplate ->set_var(array('busFace'=>getUserFace($val['usr_id']),'busName'=>$val['usr_shw_name'],'busHit'=>$val['hits'],'busTemId'=>$val['temp_userid']));
		$zTemplate->parse ( 'ContentList', 'optContent', true );
	}
}
else 
{
	$sql = "SELECT * FROM `org_details` WHERE `sort_id` = '".$tRecordSet['sort_id']."' ORDER BY `hits` DESC LIMIT 0,5";
	$rs = $db -> executeQuery($sql);
	if(is_array($rs))
	{
		foreach ($rs as $val)
		{
			if($val['temp_userid'] == $id) continue;
			$zTemplate ->set_var(array('busFace'=>getUserFace($val['usr_id']),'busName'=>$val['usr_shw_name'],'busHit'=>$val['hits'],'busTemId'=>$val['temp_userid']));
			$zTemplate->parse ( 'ContentList', 'optContent', true );
		}
	}
}
